Skip to content

Fix panic in Int::div_rem_unsigned with large divisors#1250

Open
cong-or wants to merge 1 commit intoRustCrypto:masterfrom
cong-or:fix-div-rem-unsigned-panic
Open

Fix panic in Int::div_rem_unsigned with large divisors#1250
cong-or wants to merge 1 commit intoRustCrypto:masterfrom
cong-or:fix-div-rem-unsigned-panic

Conversation

@cong-or
Copy link
Copy Markdown
Contributor

@cong-or cong-or commented Apr 10, 2026

Fix ct div_rem_unsigned blowing up on large divisors

Ran into this while poking at something unrelated.

The constant-time div_rem_unsigned breaks when the divisor gets big enough
(e.g. any U128 > I128::MAX), since the remainder can’t fit in a signed
int of the same size. The ct path was going through new_from_abs_sign,
which ends up blowing up in that case.

The vartime version doesn’t have this issue since it just uses
as_int().wrapping_neg_if(), so this switches the ct path to do the same.

Added a test with the values from the issue to make sure it doesn’t regress.

Fixes #847

   panics when the remainder's magnitude doesn't fit
  in , which happens when the divisor is large enough.
  Use  instead, matching the vartime path.

  Fixes RustCrypto#847
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.87%. Comparing base (9ba2ef6) to head (83a1c24).
⚠️ Report is 18 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1250      +/-   ##
==========================================
+ Coverage   87.99%   90.87%   +2.88%     
==========================================
  Files         184      186       +2     
  Lines       21244    21609     +365     
==========================================
+ Hits        18693    19638     +945     
+ Misses       2551     1971     -580     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in Int::div_rem_uint

1 participant